package com.atguigu.uitls;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

public class KeyWordUtil {

    public static List<String> splitKeyWord(String keyWord) throws IOException {

        //创建分词对象
        StringReader reader = new StringReader(keyWord);
        IKSegmenter ikSegmenter = new IKSegmenter(reader, false);

        //创建集合用于存放结果数据
        ArrayList<String> list = new ArrayList<>();

        //提取分好的词,将其加入集合
        Lexeme lexeme = ikSegmenter.next();

        while (lexeme != null) {
            String word = lexeme.getLexemeText();
            list.add(word);

            lexeme = ikSegmenter.next();
        }

        //返回结果
        return list;
    }

    public static void main(String[] args) throws IOException {

        System.out.println(splitKeyWord("尚硅谷大数据之Flink实时数仓"));

    }

}
